<template>
  <div>
    <el-select v-model="selectedItem" filterable placeholder="请选择" @change="ChangeData">
      <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
      </el-option>
    </el-select>
  </div>

</template>

<script>
import { listProjectinfo, getProjectinfo, delProjectinfo, addProjectinfo, updateProjectinfo } from "@/api/geoInfor/projectinfo";
import { listGeothermalwellinfo, getGeothermalwellinfo, delGeothermalwellinfo, addGeothermalwellinfo, updateGeothermalwellinfo } from "@/api/geoInfor/geothermalwellinfo";
export default {
  name: "ItemOptions",
  props: {
    queryParams: {
      require: true,
      type: Object
    },
    optionsParam: {
      require: true,
      type: String
    },
    /* selectedParam: {
      require: true,
      type: String
    } */
  },
  data() {
    return {
      selectedItem: '',
      options: {},
      dataList: [],
    }
  },
  watch: {
    /*  selectedParam(newValue) {
         this.selectedParam = Number(newValue);
       console.log(newValue)
     } */
  },
  created() {
    if (this.optionsParam == "project") {
      this.getProjectList();
    } else if (this.optionsParam == "well") {
      this.getWellList();
    }
  },
  mounted() {
    console.log(this.dataList);
    console.log(this.queryParams);
    console.log(this.optionsParam);
  },
  computed: {

  },
  methods: {
    ChangeData(select) {
      this.$emit("changeItemData", select);
      //console.log(select);
    },
    submitForm() {
      console.log(this.selectedItem)
    },
    getProjectList() {
      listProjectinfo(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.getProjectOptions(this.dataList);
      });
    },
    getWellList() {
      listGeothermalwellinfo(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.getWellOptions(this.dataList);
      });
    },
    getProjectOptions(dataList) {
      this.options = dataList.map((item) => {
        return {
          value: item.projectno,
          label: item.entryname
        }
      });
    },
    getWellOptions(dataList) {
      this.options = dataList.map((item) => {
        return {
          value: item.wellno,
          label: item.wellname
        }
      });
    },
  }
}
</script>